<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * 获取图片完整路径
 * $filed 文件夹名 
 * $filename 图片名
 */
function uploadpath($filed = '',$filename){
    if($filename){
        $file = substr($filename,0,6);
        $path = 'uploads' . "/$filed/" . "/$file/" .$filename;
        return file_exists($path) ? config('uploadPath') . "/$filed/" . "/$file/" .$filename : '';
    }else{
        return '';
    }

}
/**
 * 生成随机字符串
 *
 * @param int       $length  要生成的随机字符串长度
 * @param string    $type    随机码类型：0,数字+大小写字母；1,数字；2,小写字母；3,大写字母；4,特殊字符；-1,数字+大小写字母+特殊字符
 *
 */
function randCode($length = 6,$type = 0){
    $arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|");
    if($type == 0){
        array_pop($arr);
        $string = implode("",$arr);
    }elseif ($type == "-1"){
        $string = implode("",$arr);
    }else{
        $string = $arr[$type];
    }
    $count = strlen($string) - 1;
    $code = '';
    for ($i = 0; $i < $length; $i++) {
        $str[$i] = $string[rand(0, $count)];
        $code .= $str[$i];
    }
    return $code;
}
/**
 * 生成唯一的订单号 201808181435592323127
 * 2011-年日期
 * 08-月份
 * 09-日期
 * 11-小时
 * 12-分
 * 59-秒
 * 2323-微秒
 * 127-随机值
 * @return string
 */
function trade_no() {
    list($usec) = explode(" ", microtime());
    $usec = substr(str_replace('0.', '', $usec), 0 ,4);
    $str  = rand(1000,9999);
    return date("YmdHis").$usec.$str;
}


?>





